
// magic-string是一个操作字符串和生成source-map的工具
var MagicString = require('magic-string');
var magicString = new MagicString('export var name = "ikki"');
//剪出一个子串出来 前闭后开区间 xxx.slice(0,6) 返回一个原串的克隆
console.log(magicString.snip(0,6).toString()); //export
//删除从开始到结束的区间的内容
console.log(magicString.remove(0,7).toString()); //var name = "ikki"

//还可以用来连接多个子串
let bundleString = new MagicString.Bundle();
bundleString.addSource({
    content:'var a = 1;',
    separator: '\n'
})
bundleString.addSource({
    content: 'var b = 2;',
    separator: '\n'
});
console.log(bundleString.toString()); 
// ==>
// var a = 1;
// var b = 2;